package com.xiliu.server.modules.become.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.xiliu.common.annotation.Log;
import com.xiliu.common.controller.BaseController;
import com.xiliu.common.enums.BusinessType;
import com.xiliu.common.page.TableDataInfo;
import com.xiliu.common.result.R;
import com.xiliu.server.modules.become.entity.XlBecome;
import com.xiliu.server.modules.become.service.IXlBecomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiliu
 * @description
 * @date 2023/2/6
 */
@RestController
@RequestMapping("auth/become")
public class XlBecomeController extends BaseController {

    @Autowired
    private IXlBecomeService becomeService;

    /**
     * 查询认证列表
     */
    @PreAuthorize("@customSs.hasPermi('auth:become:list')")
    @GetMapping("/list")
    public TableDataInfo list(XlBecome become) {
        startPage();
        List<XlBecome> list = becomeService.selectXlBecomeList(become);
        return getDataTable(list);
    }

    /**
     * 获取认证表详细信息
     */
    @PreAuthorize("@customSs.hasPermi('auth:become:query')")
    @GetMapping(value = "/{becomeId}")
    public R getInfo(@PathVariable("becomeId") Long becomeId) {
        return R.ok(becomeService.selectXlBecomeByComeId(becomeId));
    }

    /**
     * 修改认证表
     */
    @PreAuthorize("@customSs.hasPermi('auth:become:edit')")
    @Log(title = "认证表", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{becomeId}")
    public R update(@PathVariable Long becomeId,  @RequestBody XlBecome xlBecome) {
        boolean success = becomeService.update(new LambdaUpdateWrapper<XlBecome>()
                .set(XlBecome::getState, xlBecome.getState())
                .set(XlBecome::getResult, xlBecome.getResult())
                .eq(XlBecome::getBecomeId,becomeId));
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除认证表
     */
    @PreAuthorize("@customSs.hasPermi('auth:become:remove')")
    @Log(title = "认证表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{houseIds}")
    public R remove(@PathVariable Long[] becomeIds) {
        return R.ok(becomeService.deleteByBecomeIds(becomeIds));
    }
}
